<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/pagelet/page-includes.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
</head>
<body class="hold-transition skin-blue sidebar-mini">
			<section class="content" style="align-content: center">
<!-- 内容开始 -->
				<div>
					<form class="form-horizontal" style="align-content: center">
						<div class="box-body">
							<div class="row rowStyle">
								<div class="col-xs-4 bs-valid">
									<label for="orgCode">机构编码: </label>
									<input type="text" class="form-control" id="orgCode" name="orgCode" value="${sysOrg.orgCode }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgName">机构名称: </label>
									<input type="text" class="form-control" id="orgName" name="orgName" value="${sysOrg.orgName }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgStatus">机构状态: </label>
									<asone:tag type="select" table="t_sys_dict" where="dict_code='asone_sysOrg_status'" fieldName="dict_remark" fieldValue="dict_value" top="false" checkValue="${sysOrg.orgStatus }" tagAttr="class='form-control' id='orgStatus' name='orgStatus' "></asone:tag>
								</div>
							</div>
							<div class="row rowStyle">
								<div class="col-xs-4 bs-valid">
									<label for="parentOrgName">父级机构: </label>
									<input type="text" class="form-control" onclick="showMenu('parentOrgName');" id="parentOrgName" name="parentOrgName" value="${sysOrg.parentOrgName }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="parentOrgCode">父级机构编码: </label>
									<input type="text" class="form-control" readonly="readonly" id="parentOrgCode" name="parentOrgCode" value="${sysOrg.parentOrgCode }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgLevel">机构等级: </label>
									<asone:tag type="select" table="t_sys_dict" where="dict_code='asone_sysOrg_level'" fieldName="dict_remark" fieldValue="dict_value" top="false" checkValue="${sysOrg.orgLevel }" tagAttr="class='form-control' id='orgLevel' name='orgLevel' "></asone:tag>
								</div>
							</div>
							<div class="row rowStyle">
								<div class="col-xs-4 bs-valid">
									<label for="orgContact">联系人: </label>
									<input type="text" class="form-control" id="orgContact" name="orgContact" value="${sysOrg.orgContact }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgTel">联系电话: </label>
									<input type="text" class="form-control" id="orgTel" name="orgTel" value="${sysOrg.orgTel }">
								</div>
								<div class="col-xs-4 bs-valid">
									<label for="orgEmail">邮箱地址: </label>
									<input type="text" class="form-control" id="orgEmail" name="orgEmail" value="${sysOrg.orgEmail }">
								</div>
							</div>
							<div class="row rowStyle">
								<div class="col-xs-12 bs-valid">
									<label for="orgAddr">联系地址: </label>
									<input type="text" class="form-control" id="orgAddr" name="orgAddr" value="${sysOrg.orgAddr }">
								</div>
							</div>
							<div class="row row-textarea3">
								<div class="col-xs-12 bs-valid">
									<label for="remark">备注: </label>
									<textarea class="form-control" id="remark" name="remark" rows="3" placeholder="Enter ...">${sysOrg.remark }</textarea>
								</div>
							</div>
						</div>
						<div class="box-footer text-center">
							<input type="hidden" name="id" id="id" value="${sysOrg.id }" />
							<button type="button" class="btn btn-primary saveBtn" onclick="save()">保存</button>
						</div>
					</form>
				</div>
				<div id="treeDiv" class="treeDiv" style="display:none; position: absolute;">
					<ul id="treeUl" class="ztree" style="margin-top:0; width:160px;"></ul>
				</div>
<!-- 内容结束 -->
			</section>
</body>

<script type="text/javascript">

var index = parent.layer.getFrameIndex(window.name);

onload = function(){
	
	//机构树
	var setting = {
		view: {
			selectedMulti: false
		},
		async: {
			enable: true,
			url:"${webroot}/sysorg/getjsondata",
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClickTree
		}
	};
	$.fn.zTree.init($("#treeUl"), setting);
	
	
	//添加校验表单
	$('.form-horizontal').bootstrapValidator({
		message: '输入错误',
		feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
        	orgCode : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[0-9]{12}$/,message: '机构编码为12个数字'}
        		}
        	},
        	orgName : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5]{1,200}$/, message: '机构名称为1~200个字符，不能包含特殊字符'}
        		}
        	},
        	orgContact : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5]{1,100}$/, message: '机构联系人为1！100个字符，不能包含特殊字符'}
        		}
        	},
        	orgTel : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^1[3|4|5|8][0-9]\d{4,8}$/, message: '请输入正确的手机号码'}
        		}
        	},
        	orgEmail : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, message: '请输入正确的电子邮箱'}
        		}
        	},
        	orgAddr : {
        		validators : {
        			notEmpty: {message: '该项不能为空'},
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5]{1,300}$/, message: '联系地址为1~300个字符，不能包含特殊字符'}
        		}
        	},
        	remark : {
        		validators : {
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5，。 ]{0,300}$/, message: '备注不能超过300个字符，不能包含特殊字符'}
        		}
        	}
        }
	})
}


function onClickTree(e, treeId, treeNode) {
	var orgCode = "${sysOrg.orgCode }";
	var zTree = $.fn.zTree.getZTreeObj("treeUl"),
	nodes = zTree.getSelectedNodes(),
	name = "";
	value = "";
	nodes.sort(function compare(a,b){return a.id-b.id;});
	for (var i=0, l=nodes.length; i<l; i++) {
		value += nodes[i].id + ",";
		name += nodes[i].name + ",";
	}
	if (value.length > 0 ) value = value.substring(0, value.length-1);
	if (name.length > 0 ) name = name.substring(0, name.length-1);
	
	if(orgCode == value){
		app.print.error("父级机构不能为自己", null, null);
		return;
	}
	$("#parentOrgName").val(name);
	$("#parentOrgCode").val(value);
	
	hideMenu();
}


function save() {
	$('.form-horizontal').bootstrapValidator('validate');
	if(!$('.form-horizontal').data('bootstrapValidator').isValid()) return;
	var id = "${sysOrg.id}";
	var flag = "";
	if(id != null && id!= ""){
		flag = "UPDATE";
	}
	$.ajax({
		type: "POST",
		url: webroot + "/sysorg/modify?showtype=" + flag,
		data:$('.form-horizontal').serialize(),
		dataType: "json",
		success: function(resp){
			if(resp.success){
				app.print.success("保存成功!", index,null)
			} else {
				app.print.error(resp.message, null, null);
			}
		}
	});
}
</script>

</html>
